package com.itheima;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.IllegalFormatCodePointException;

public class ServletDemo5 extends HttpServlet {

    @Override
//req 包含客户端对 servlet 发出的请求的 HttpServletRequest 对象
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
         int money=1000;
        String name=req.getRequestURI();
         name = name.substring(name.lastIndexOf("/"));
        if ("/vip".equals(name)){
            //如果访问资源路径是/vip 商品价格为9折
            System.out.println("商品原价是:"+money+"优惠后是:"+(money*0.9));
        }else if ("/vvip".equals(name)){
            System.out.println("商品原价是:"+money+"优惠后是:"+(money*0.5));
        }else{
            System.out.println("商品价格是:"+money);
        }
    }

    @Override
//    resp 包含 servlet 向客户端发送的响应的 HttpServletResponse 对象
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        super.doPost(req, resp);
    }
}
